﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SkyDotNet
{
    class QuestionGenerator
    {
        public static Question Generate(int responsesNb, string folderPath)
        {
            Question newQuestion = new Question();

            List<string> filesWithAbsolutePath = Directory.GetFiles(folderPath).ToList();

            Random randomizer = new Random();

            for (int i = 0; i < responsesNb; i++)
            {
                int selectedIndex = randomizer.Next(filesWithAbsolutePath.Count);
                string selectedFile = filesWithAbsolutePath.ElementAt(selectedIndex);
                filesWithAbsolutePath.RemoveAt(selectedIndex);

                // La première réponse générée sera celle à retrouver
                if (i == 0)
                    newQuestion.rightResponse = selectedFile.Substring(selectedFile.LastIndexOf(@"\") + 1).Split('.').First();
                else
                    newQuestion.otherResponses.Add(selectedFile.Substring(selectedFile.LastIndexOf(@"\") + 1).Split('.').First());
            }

            return newQuestion;
        }
    }
}
